package com.cyufeng.blog.service;

import com.cyufeng.blog.dto.ArticleDto;
import com.cyufeng.blog.dto.ReprintDto;
import com.cyufeng.blog.entity.Article;
import com.cyufeng.blog.entity.Reprint;
import com.cyufeng.blog.entity.Review;
import com.cyufeng.blog.repository.ReprintRepository;
import com.cyufeng.blog.service.mapper.ReprintMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 转载文章
 * @author Cyufeng
 * Data:2019.01.07
 */
@Service
public class ReprintService {
    @Autowired
    ReprintRepository reprintRepository;
ReprintMapper reprintMapper = new ReprintMapper();
    public String saveReprint(ReprintDto reprintDto){
        try {
//            将从前台传来的dto通过mapper转为entity再保存entity
            Reprint reprint = new Reprint();
            reprint = reprintMapper.dtoToentity(reprintDto);
            reprint.setMadeTime(new Date());
//            reprint.setCode(setCode.setcode());
            reprintRepository.save(reprint);
////            将新增的entity的id和title字段保存到审批表里面
//            Review review = new Review();
//            review.setArticleCode(article.getCode());//设置文章的唯一标示
//            review.setArticleTitle(article.getTitle());//设置文章标题
//            review.setIsEnable(0);//是否审批，这个字段会和文章表里面的字段同步
//            review.setDr(0);//是否删除
//            review.setMadeTime(new Date());//创建时间
//            reviewRepository.save(review);

            return "success";
        } catch (Exception e) {
            return "error";
        }
    }
}
